package collections3;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

import org.omg.PortableInterceptor.DISCARDING;

public class EqualsFilename {

	public static void main(String[] args) {
		// 输入两个文件名，比较其是否是相同的。不考虑文件夹。
		Scanner input = new Scanner(System.in);
		System.out.println("输入文件1名：");
		String s1 = input.nextLine();
		System.out.println("输入文件2名：");
		String s2 = input.nextLine();
		FileInputStream fis = null;
		DataInputStream dis = null;
		FileInputStream fis2 = null;
		DataInputStream dis2 = null;
		try {
			int c = s1.lastIndexOf(".");
			int d = s2.lastIndexOf(".");
			String houzhui1 = s1.substring((c + 1), s1.length());// 文件1的后缀
			String houzhui2 = s2.substring((d + 1), s2.length());// 文件2的后缀
			fis = new FileInputStream(s1);
			dis = new DataInputStream(fis);
			fis2 = new FileInputStream(s2);
			dis2 = new DataInputStream(fis2);
			boolean isright = true;
			if (houzhui1.equals(houzhui2)) {
				int e, f;
				while (((e = dis.read()) != -1) && ((f = dis2.read()) != -1)) {
					if (e != f) {
						isright = false;
						break;
					}
				}
				System.out.println("两个文件相等？" + isright);
			} else {
				isright=false;
				System.out.println("两个文件相等？" + isright);
			}
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} finally {

			try {
				dis.close();
				dis2.close();
			} catch (IOException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}
	}
}
